package com.sjk.mapper;/*
 * @author 86136
 * @create 2023/5/15 20:47
 */

import com.sjk.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {
    // 密文显示
    @Select("select username,gender,age,name,birthdate,phonenum_encrypt,id_encrypt,address from user limit #{page},#{pageSize}")
    List<User> selectAll0(@Param("page") int page,@Param("pageSize") int pageSize);

    // 明文显示
    @Select("select username,gender,age,name,birthdate,phonenum,id,address from user limit #{page},#{pageSize}")
    List<User> selectAll1(@Param("page") int page,@Param("pageSize") int pageSize);

    // 手机号查询,管理员权限
    @Select("select username,gender,age,name,birthdate,phonenum_encrypt,id_encrypt,address from user where phonenum_encrypt=#{phonenum_encrypt}")
    List<User> selectByAllPhonenum0(String phonenum_encrypt);

    // 手机号查询,超管权限
    @Select("select username,gender,age,name,birthdate,phonenum,id,address from user where phonenum_encrypt=#{phonenum_encrypt}")
    List<User> selectByAllPhonenum1(String phonenum_encrypt);

    // 手机号后四位查询,管理员权限
    @Select("select username,gender,age,name,birthdate,phonenum_encrypt,id_encrypt,address from user where phonenum4_encrypt=#{phonenum4_encrypt}")
    List<User> selectBy4Phonenum0(String phonenum4_encrypt);

    // 手机号后四位查询,超管权限
    @Select("select username,gender,age,name,birthdate,phonenum,id,address from user where phonenum4_encrypt=#{phonenum4_encrypt}")
    List<User> selectBy4Phonenum1(String phonenum4_encrypt);

    // 身份证号查询,管理员权限
    @Select("select username,gender,age,name,birthdate,phonenum_encrypt,id_encrypt,address from user where id_encrypt=#{id_encrypt}")
    List<User> selectByAllId0(String id_encrypt);

    // 身份证号查询,超管权限
    @Select("select username,gender,age,name,birthdate,phonenum,id,address from user where id_encrypt=#{id_encrypt}")
    List<User> selectByAllId1(String id_encrypt);

    // 身份证号后6位查询,管理员权限
    @Select("select username,gender,age,name,birthdate,phonenum_encrypt,id_encrypt,address from user where id6_encrypt=#{id6_encrypt}")
    List<User> selectBy6Id0(String id6_encrypt);

    // 身份证号后6位查询,超管权限
    @Select("select username,gender,age,name,birthdate,phonenum,id,address from user where id6_encrypt=#{id6_encrypt}")
    List<User> selectBy6Id1(String id6_encrypt);

    // 删除时使用手机号查找
    @Select("select username,gender,age,name,birthdate,phonenum,id_encrypt,address from user where phonenum_encrypt=#{phonenum_encrypt}")
    List<User> deleteSelectByAllPhonenum(String phonenum_encrypt);

    // 删除用户
    @Delete("delete from user where phonenum_encrypt=#{phonenum_encrypt}")
    void deleteByAllPhonenum(String phonenum_encrypt);

    // 修改时使用手机号查找
    @Select("select username,gender,age,name,birthdate,phonenum,id_encrypt,address from user where phonenum_encrypt=#{phonenum_encrypt}")
    List<User> updateSelectByAllPhonenum(String phonenum_encrypt);

    // 修改用户信息
    @Update("update user set username = #{username}, phonenum = #{phonenum}, phonenum_encrypt=#{phonenum_encrypt}, phonenum4_encrypt=#{phonenum4_encrypt}, address = #{address} where name = #{name}")
    void updateUser(User user);

    // 添加用户
    @Insert("insert into user(username,password,gender,age,name,birthdate,phonenum,phonenum_encrypt,phonenum4_encrypt,id,id_encrypt,id6_encrypt,address,authority) values(#{username},#{password},#{gender},#{age},#{name},#{birthdate},#{phonenum},#{phonenum_encrypt},#{phonenum4_encrypt},#{id},#{id_encrypt},#{id6_encrypt},#{address},#{authority})")
    void insertUser(User user);
}
